/*
 * Copyright 2002-2006 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package pikes.samples.countries.ui.peak;

import java.util.LinkedHashMap;
import java.util.Map;

import pikes.peak.Composite;
import pikes.peak.Label;
import pikes.peak.LabelStyle;
import pikes.peak.ListComposite;
import pikes.peak.Text;
import pikes.peak.Paragraph;
import pikes.peak.TextGroupStyle;
import pikes.uri.RelativeURI;
import pikes.uri.WebLink;

public class HomePage extends BehaviourPage {

	@Override
	protected String getTitle() {
		return "home.htitle";
	}

	@Override
	protected void buildContent(Composite content) {

		WebLink springHomePage = new WebLink("www.springframework.org");
		/*
		 * URI springHomePage = new URI() { @Override protected void buildContextPath(Appendable uriString, Map model,
		 * RequestContext requestContext) throws Exception { uriString.append("www.springframework.org"); } @Override
		 * protected void buildPath(Appendable uriString, Map model, RequestContext requestContext) throws Exception { //
		 * no path in this URI } @Override protected void buildScheme(Appendable uriString, Map model, RequestContext
		 * requestContext) throws Exception { uriString.append("http://"); } };
		 */

		Map<CharSequence, CharSequence> parameters = new LinkedHashMap<CharSequence, CharSequence>();
		parameters.put("group_id", "73357");
		RelativeURI springDownload = new RelativeURI(new WebLink("sourceforge.net"), "project/showfiles.php",
				parameters);
		/*
		 * URI springDownload = new URI() { @Override protected void buildContextPath(Appendable uriString, Map model,
		 * RequestContext requestContext) throws Exception { uriString.append("sourceforge.net"); } @Override protected
		 * void buildPath(Appendable uriString, Map model, RequestContext requestContext) throws Exception {
		 * uriString.append("/project/showfiles.php?group_id=73357"); } @Override protected void buildScheme(Appendable
		 * uriString, Map model, RequestContext requestContext) throws Exception { uriString.append("http://"); } };
		 */

		ListComposite featureList = new ListComposite();
		Composite featureListDiv = new Composite();

		Paragraph versionParagraph = new Paragraph("version ");
		Composite info = new Composite();
		Composite news = new Composite();

		Label springHomePageLabel = new Label("SpringFramework", LabelStyle.STRONG);
		Label springFramework = new Label("SpringFramework", LabelStyle.STRONG);

		news.setClazz("news");
		news.add(new Label("app.desc1"));

		springHomePageLabel.setURI(springHomePage);
		news.add(springHomePageLabel);

		news.add(new Label("app.desc2"));
		news.add(Label.LINE_BREAK);
		news.add(new Label("app.desc3"));

		versionParagraph.add(new Label("app.version", LabelStyle.STRONG));
		versionParagraph.setClazz("version");

		featureList.add(new Label("app.feature1"));

		featureList.add(new Label("app.feature2"));
		featureList.add(new Label("app.feature3"));
		featureList.add(new Label("app.feature4"));
		featureList.add(new Label("app.feature5"));
		featureList.add(new Label("app.feature6"));
		featureList.add(new Label("app.feature7"));

		featureListDiv.add(featureList);

		news.add(featureListDiv);

		info.setClazz("info");
		info.add(new Label("home.sources1"));

		springFramework.setURI(springDownload);
		info.add(springFramework);

		info.add(new Label("home.sources2"));
		info.add(new Text("0.9.1"));
		info.add(new Label("home.sources3"));
		info.add(new Text("."));

		content.add(new Paragraph("home.title", TextGroupStyle.LEVEL_2));
		content.add(new Paragraph(Label.SPACE));
		content.add(new Paragraph("app.name", TextGroupStyle.LEVEL_3));

		content.add(versionParagraph);

		content.add(news);

		content.add(info);
	}

}
